<?php
namespace App\Controllers;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

use App\Models\PowerModel;
use stdClass;
 date_default_timezone_set('prc');
class PowerController extends BaseController {
	
	public function PowerList($request, $response, $args) {
		include APP_PATH . '/Views/Power/list.html';
	}
	
	public function PowerInfo($request, $response, $args) {
		
		$Rolename=$request -> getParam('rolename');
		$user = new PowerModel();
		$result=$user -> Powerselect($Rolename);
		
		$draw=$request->getParam('draw')*1;//第几次请求
		$start=$request->getParam('start');//第一条数据开始的索引
		$length=$request->getParam('length');//返回的数据长度
		$newarr = new stdClass();
		$newarr->draw = $draw;
		$newarr->page = count($result)/$length;
		$newarr->recordsTotal = count($result);
		$newarr->recordsFiltered = count($result);
		$newarr->data = array();
		$h=0;
		for($i = $start; $i<$start+$length;$i++,$h++)
			{   if(!empty($result[$i])){
				$newarr->data[$h] = $result[$i];
				}else{
					break;
				}
						
			}
				return $newResponse = $response->withJson($newarr, 200);
		}
	
}
?>
